<?php
/**
 * created by zzy
 * date: 2018/1/26 14:07
 */


namespace App\Http\Admin\Logistics\Controllers;

use App\Eloquent\Ygt\LogisticsNotes;
use Framework\BaseClass\Http\Admin\Controller;

class NotesController extends Controller
{
    public function lists()
    {
        $adminUser          = request()->user('admin')->toArray();
        $companyId          = $adminUser['company_id'];
        $logisticsId        = request('logistics_id',0);
        if (request()->isMethod('post')) {

            $pageSize       = request('pageSize', 30);
            $pageCurrent    = request('pageCurrent', 1);
            $offset         = ($pageCurrent - 1) * $pageSize;

            $where          = ['company_id'=>$companyId,'logistics_id'=>$logisticsId];
            $lists          = LogisticsNotes::getList($where,'',$pageSize,$offset)->toArray();
            $count          = LogisticsNotes::getCount($where);
            $isRemindFinishArr  = [0=>'不提醒',1=>'提醒'];
            foreach($lists as $key=>$val)
            {
                $valIsRemindFinish  = $val['is_remind_finish'];
                $customerAddress    = $val['province_name'].$val['city_name'].$val['area_name'].$val['address'];
                $lists[$key]['is_remind_finish'] = $isRemindFinishArr[$valIsRemindFinish];
                $lists[$key]['customer_address'] = $customerAddress;
            }
            $data           = ['totalRow'=>$count,'pageCurrent'=>$pageCurrent,'list'=>$lists];
            $result         = json_encode($data);
            return $result;
        } else {
            return $this->view('lists',compact('logisticsId'));
        }
    }
    public function edit()
    {
        $adminUser          = request()->user('admin')->toArray();
        $companyId          = $adminUser['company_id'];

        $data                   = request()->all();
        $data['company_id']    = $companyId;
        $fieldList              = LogisticsNotes::$tableFieldList;
        $tableData              = LogisticsNotes::setDataByTableField($data,$fieldList);
        $tableDataCheckResult   = LogisticsNotes::checkDataByTableField($tableData,$fieldList);
        if($tableDataCheckResult !== true)
        {
            xThrow(ERR_PARAMETER, $tableDataCheckResult);
        }
        $result                 = LogisticsNotes::edit($tableData);
        if( $result ){
            return $this->ajaxSuccess( '成功' );
        } else {
            return $this->ajaxFail( '失败' );
        }
    }
    public function delete(){}

}